package com.apartment.own.controller;


import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;

import com.apartment.common.utils.CollectionHelper;
import com.apartment.own.domain.OwnSystemArea;
import com.apartment.own.response.res.CommonGroupResponse;
import com.apartment.own.service.IOwnSystemAreaService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description:地区码Controller
 * @Author: @Dog_E
 * @Date: 2020/9/10 0010 09:25
 **/
@RequestMapping("/own/area")
@RestController
@Api(value = "地区", tags = "地区")
public class OwnSystemAreaController extends BaseController {

    @Autowired
    private IOwnSystemAreaService ownSystemAreaService;

    /**
     * 首字母排序
     * @return 地区码集合
     */
    @GetMapping("/list")
    @ApiOperation("市地区安装首字母排序")
    public AjaxResult selectInitialSort() {
        List<OwnSystemArea> list = ownSystemAreaService.selectInitialSort();

        Map<String, List<OwnSystemArea>> getInitial = new
                CollectionHelper<OwnSystemArea>()
                .groupObjectBy(list, "getInitial");

        ArrayList<CommonGroupResponse> responses = new ArrayList<>();
        getInitial.forEach((k,v)->{
            responses.add(new CommonGroupResponse(k,v));
        });
        return AjaxResult.success(responses);
    }

}
